import { request } from '@/api'; // 使用别名 @ 来指向 src 目录
import { closeToast, showLoadingToast, showToast } from 'vant';
import { onMounted, ref } from 'vue';
import base64ToBlob from 'b64-to-blob';
// 1. 修改头像
// 1.1 控制修改头像弹层的显示/隐藏，是否显示 拍照，相册交互弹窗
/**
 * 1.拍照，或者相册，获取选择的图片信息
 * 2.根据接口文档提交数据
 * 3，本地更新投邮箱信息即可
 */
const showAvatarSheet = ref(false);
// 1.2 打开相册/相机
const onSelectAvatar = async (item, i) => {
    if (i === 0) {
        // 相册上传
        // console.log('相册上传')
        const data = await mk.pickerPhoto();
        await onUpdateAvatar(data);
    }
    else if (i === 1) {
        // 拍照上传
        // console.log('拍照上传')
        const data = await mk.pickerCamera();
        await onUpdateAvatar(data);
    }
};
// 1.3 头像上传
const onUpdateAvatar = async (data) => {
    try {
        showAvatarSheet.value = false;
        showLoadingToast({ message: '正在上传', duration: 0, forbidClick: true });
        // base64转 二进制
        const image = base64ToBlob(data, 'image/jpeg');
        // 创建一个转载数据的formData对象
        const fd = new FormData();
        // 追加数据
        // file key
        // img数据
        // 参数3名字
        fd.append('file', image, Date.now() + '.jpeg');
        // 调用上传接口，根据接口文档设置地址和方法，formData 设置到参数2即可
        const res = await request.post('member/profile/avatar', fd);
        // 修改页面显示
        profile.value.avatar = URL.createObjectURL(image);
        // 获取保存在鸿蒙缓存中用户信息
        const user = mk.queryUser();
        // 修改用户信息的头像 为上传成功之后的头像
        user.avatar = res.data.result.avatar;
        // 更新鸿蒙端的头像
        mk.updateUser(user);
        showToast({ message: '上传成功' });
    }
    catch (err) {
        showToast({ message: '上传失败' });
    }
};
// 2. 选择生日日期
const showBirthdayPopup = ref(false);
const onChangeBirthday = () => {
    // console.log(currentDate.value)
    showBirthdayPopup.value = false;
    profile.value.birthday = currentDate.value.join('-');
};
const currentDate = ref(['2000', '02', '03']);
// 3. 选择所在地
const areaColumns = ref();
const showLocationPopup = ref(false);
onMounted(async () => {
    const data = await mk.getAreaColumns();
    areaColumns.value = data;
    console.log(data);
});
const onSelectedLocation = (data) => {
    showLocationPopup.value = false;
    console.log(data);
    // console.log(data.selectedOptions)
    const arr = data.selectedOptions.map((v) => {
        return v.text;
    });
    // 修改页面渲染的省市区
    profile.value.fullLocation = arr.join(' ');
    // 修改提交数据中的 省市区
    profile.value.provinceCode = data.selectedValues[0];
    profile.value.cityCode = data.selectedValues[1];
    profile.value.countyCode = data.selectedValues[2];
};
// 4. 选择职业
// 职业列表
const columns = [
    { text: '软件工程师', value: '软件工程师' },
    { text: '医生', value: '医生' },
    { text: '教师', value: '教师' },
    { text: '律师', value: '律师' },
    { text: '会计师', value: '会计师' },
    { text: '销售经理', value: '销售经理' },
    { text: '市场营销专员', value: '市场营销专员' },
    { text: '建筑师', value: '建筑师' },
    { text: '护士', value: '护士' },
    { text: '机械工程师', value: '机械工程师' },
];
// 是否显示
const showProfessionPopup = ref(false);
// 点击提交
const onChangeProfession = (data) => {
    // console.log(data)
    showProfessionPopup.value = false;
    profile.value.profession = data.selectedValues.join('');
};
// 获取用户信息
const profile = ref({});
onMounted(async () => {
    showLoadingToast({ message: '加载中...', duration: 0, forbidClick: true });
    const res = await request.get('member/profile');
    closeToast();
    profile.value = res.data.result;
    // 生日
    currentDate.value = profile.value.birthday.split('-');
});
// 保存资料
const loading = ref(false);
const onSubmit = async () => {
    console.log(profile.value);
    // mk.vibrator()
    loading.value = true;
    const res = await request.put('member/profile', profile.value);
    console.log(res);
    loading.value = false;
    mk.updateUser(res.data.result);
    showToast({ message: '保存成功' });
}; /* PartiallyEnd: #3632/scriptSetup.vue */
function __VLS_template() {
    const __VLS_ctx = {};
    let __VLS_components;
    let __VLS_directives;
    // CSS variable injection 
    // CSS variable injection end 
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
        ...{ class: ("profile-edit-page") },
    });
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
        ...{ class: ("avatar") },
    });
    const __VLS_0 = {}.VanImage;
    /** @type { [typeof __VLS_components.VanImage, typeof __VLS_components.vanImage, typeof __VLS_components.VanImage, typeof __VLS_components.vanImage, ] } */ ;
    // @ts-ignore
    const __VLS_1 = __VLS_asFunctionalComponent(__VLS_0, new __VLS_0({
        ...{ 'onClick': {} },
        round: (true),
        width: ("100"),
        height: ("100"),
        ...{ class: ("avatar-img") },
        src: ("https://foruda.gitee.com/avatar/1716533299289369832/5539886_yjh8866_1716533299.png"),
    }));
    const __VLS_2 = __VLS_1({
        ...{ 'onClick': {} },
        round: (true),
        width: ("100"),
        height: ("100"),
        ...{ class: ("avatar-img") },
        src: ("https://foruda.gitee.com/avatar/1716533299289369832/5539886_yjh8866_1716533299.png"),
    }, ...__VLS_functionalComponentArgsRest(__VLS_1));
    let __VLS_6;
    const __VLS_7 = {
        onClick: (...[$event]) => {
            __VLS_ctx.showAvatarSheet = true;
        }
    };
    let __VLS_3;
    let __VLS_4;
    var __VLS_5;
    const __VLS_8 = {}.VanActionSheet;
    /** @type { [typeof __VLS_components.VanActionSheet, typeof __VLS_components.vanActionSheet, typeof __VLS_components.VanActionSheet, typeof __VLS_components.vanActionSheet, ] } */ ;
    // @ts-ignore
    const __VLS_9 = __VLS_asFunctionalComponent(__VLS_8, new __VLS_8({
        ...{ 'onSelect': {} },
        show: ((__VLS_ctx.showAvatarSheet)),
        actions: (([{ name: '相册' }, { name: '拍照' }])),
        cancelText: ("取消"),
        ...{ style: (({ paddingBottom: '20px' })) },
    }));
    const __VLS_10 = __VLS_9({
        ...{ 'onSelect': {} },
        show: ((__VLS_ctx.showAvatarSheet)),
        actions: (([{ name: '相册' }, { name: '拍照' }])),
        cancelText: ("取消"),
        ...{ style: (({ paddingBottom: '20px' })) },
    }, ...__VLS_functionalComponentArgsRest(__VLS_9));
    let __VLS_14;
    const __VLS_15 = {
        onSelect: (__VLS_ctx.onSelectAvatar)
    };
    let __VLS_11;
    let __VLS_12;
    var __VLS_13;
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
        ...{ class: ("avatar-btn") },
    });
    __VLS_elementAsFunction(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({
        ...{ onClick: (...[$event]) => {
                __VLS_ctx.showAvatarSheet = true;
            } },
    });
    const __VLS_16 = {}.VanCellGroup;
    /** @type { [typeof __VLS_components.VanCellGroup, typeof __VLS_components.vanCellGroup, typeof __VLS_components.VanCellGroup, typeof __VLS_components.vanCellGroup, ] } */ ;
    // @ts-ignore
    const __VLS_17 = __VLS_asFunctionalComponent(__VLS_16, new __VLS_16({}));
    const __VLS_18 = __VLS_17({}, ...__VLS_functionalComponentArgsRest(__VLS_17));
    const __VLS_22 = {}.VanField;
    /** @type { [typeof __VLS_components.VanField, typeof __VLS_components.vanField, typeof __VLS_components.VanField, typeof __VLS_components.vanField, ] } */ ;
    // @ts-ignore
    const __VLS_23 = __VLS_asFunctionalComponent(__VLS_22, new __VLS_22({
        modelValue: ((__VLS_ctx.profile.account)),
        label: ("账号"),
        readonly: (true),
    }));
    const __VLS_24 = __VLS_23({
        modelValue: ((__VLS_ctx.profile.account)),
        label: ("账号"),
        readonly: (true),
    }, ...__VLS_functionalComponentArgsRest(__VLS_23));
    const __VLS_28 = {}.VanField;
    /** @type { [typeof __VLS_components.VanField, typeof __VLS_components.vanField, typeof __VLS_components.VanField, typeof __VLS_components.vanField, ] } */ ;
    // @ts-ignore
    const __VLS_29 = __VLS_asFunctionalComponent(__VLS_28, new __VLS_28({
        modelValue: ((__VLS_ctx.profile.nickname)),
        label: ("昵称"),
        placeholder: ("请输入昵称"),
    }));
    const __VLS_30 = __VLS_29({
        modelValue: ((__VLS_ctx.profile.nickname)),
        label: ("昵称"),
        placeholder: ("请输入昵称"),
    }, ...__VLS_functionalComponentArgsRest(__VLS_29));
    const __VLS_34 = {}.VanCell;
    /** @type { [typeof __VLS_components.VanCell, typeof __VLS_components.vanCell, typeof __VLS_components.VanCell, typeof __VLS_components.vanCell, ] } */ ;
    // @ts-ignore
    const __VLS_35 = __VLS_asFunctionalComponent(__VLS_34, new __VLS_34({
        title: ("性别"),
        ...{ class: ("gender") },
    }));
    const __VLS_36 = __VLS_35({
        title: ("性别"),
        ...{ class: ("gender") },
    }, ...__VLS_functionalComponentArgsRest(__VLS_35));
    const __VLS_40 = {}.VanRadioGroup;
    /** @type { [typeof __VLS_components.VanRadioGroup, typeof __VLS_components.vanRadioGroup, typeof __VLS_components.VanRadioGroup, typeof __VLS_components.vanRadioGroup, ] } */ ;
    // @ts-ignore
    const __VLS_41 = __VLS_asFunctionalComponent(__VLS_40, new __VLS_40({
        modelValue: ((__VLS_ctx.profile.gender)),
        iconSize: ((16)),
    }));
    const __VLS_42 = __VLS_41({
        modelValue: ((__VLS_ctx.profile.gender)),
        iconSize: ((16)),
    }, ...__VLS_functionalComponentArgsRest(__VLS_41));
    const __VLS_46 = {}.VanRadio;
    /** @type { [typeof __VLS_components.VanRadio, typeof __VLS_components.vanRadio, typeof __VLS_components.VanRadio, typeof __VLS_components.vanRadio, ] } */ ;
    // @ts-ignore
    const __VLS_47 = __VLS_asFunctionalComponent(__VLS_46, new __VLS_46({
        name: ("男"),
    }));
    const __VLS_48 = __VLS_47({
        name: ("男"),
    }, ...__VLS_functionalComponentArgsRest(__VLS_47));
    __VLS_51.slots.default;
    var __VLS_51;
    const __VLS_52 = {}.VanRadio;
    /** @type { [typeof __VLS_components.VanRadio, typeof __VLS_components.vanRadio, typeof __VLS_components.VanRadio, typeof __VLS_components.vanRadio, ] } */ ;
    // @ts-ignore
    const __VLS_53 = __VLS_asFunctionalComponent(__VLS_52, new __VLS_52({
        name: ("女"),
    }));
    const __VLS_54 = __VLS_53({
        name: ("女"),
    }, ...__VLS_functionalComponentArgsRest(__VLS_53));
    __VLS_57.slots.default;
    var __VLS_57;
    const __VLS_58 = {}.VanRadio;
    /** @type { [typeof __VLS_components.VanRadio, typeof __VLS_components.vanRadio, typeof __VLS_components.VanRadio, typeof __VLS_components.vanRadio, ] } */ ;
    // @ts-ignore
    const __VLS_59 = __VLS_asFunctionalComponent(__VLS_58, new __VLS_58({
        name: ("未知"),
    }));
    const __VLS_60 = __VLS_59({
        name: ("未知"),
    }, ...__VLS_functionalComponentArgsRest(__VLS_59));
    __VLS_63.slots.default;
    var __VLS_63;
    __VLS_45.slots.default;
    var __VLS_45;
    __VLS_39.slots.default;
    var __VLS_39;
    const __VLS_64 = {}.VanField;
    /** @type { [typeof __VLS_components.VanField, typeof __VLS_components.vanField, typeof __VLS_components.VanField, typeof __VLS_components.vanField, ] } */ ;
    // @ts-ignore
    const __VLS_65 = __VLS_asFunctionalComponent(__VLS_64, new __VLS_64({
        ...{ 'onClick': {} },
        label: ("生日"),
        readonly: (true),
        placeholder: ("请选择日期"),
        modelValue: ((__VLS_ctx.profile.birthday)),
    }));
    const __VLS_66 = __VLS_65({
        ...{ 'onClick': {} },
        label: ("生日"),
        readonly: (true),
        placeholder: ("请选择日期"),
        modelValue: ((__VLS_ctx.profile.birthday)),
    }, ...__VLS_functionalComponentArgsRest(__VLS_65));
    let __VLS_70;
    const __VLS_71 = {
        onClick: (...[$event]) => {
            __VLS_ctx.showBirthdayPopup = true;
        }
    };
    let __VLS_67;
    let __VLS_68;
    var __VLS_69;
    const __VLS_72 = {}.VanField;
    /** @type { [typeof __VLS_components.VanField, typeof __VLS_components.vanField, typeof __VLS_components.VanField, typeof __VLS_components.vanField, ] } */ ;
    // @ts-ignore
    const __VLS_73 = __VLS_asFunctionalComponent(__VLS_72, new __VLS_72({
        ...{ 'onClick': {} },
        label: ("所在地"),
        readonly: (true),
        placeholder: ("选择省市区"),
        modelValue: ((__VLS_ctx.profile.fullLocation)),
    }));
    const __VLS_74 = __VLS_73({
        ...{ 'onClick': {} },
        label: ("所在地"),
        readonly: (true),
        placeholder: ("选择省市区"),
        modelValue: ((__VLS_ctx.profile.fullLocation)),
    }, ...__VLS_functionalComponentArgsRest(__VLS_73));
    let __VLS_78;
    const __VLS_79 = {
        onClick: (...[$event]) => {
            __VLS_ctx.showLocationPopup = true;
        }
    };
    let __VLS_75;
    let __VLS_76;
    var __VLS_77;
    const __VLS_80 = {}.VanField;
    /** @type { [typeof __VLS_components.VanField, typeof __VLS_components.vanField, typeof __VLS_components.VanField, typeof __VLS_components.vanField, ] } */ ;
    // @ts-ignore
    const __VLS_81 = __VLS_asFunctionalComponent(__VLS_80, new __VLS_80({
        ...{ 'onClick': {} },
        label: ("职业"),
        readonly: (true),
        placeholder: ("请选择职业"),
        modelValue: ((__VLS_ctx.profile.profession)),
    }));
    const __VLS_82 = __VLS_81({
        ...{ 'onClick': {} },
        label: ("职业"),
        readonly: (true),
        placeholder: ("请选择职业"),
        modelValue: ((__VLS_ctx.profile.profession)),
    }, ...__VLS_functionalComponentArgsRest(__VLS_81));
    let __VLS_86;
    const __VLS_87 = {
        onClick: (...[$event]) => {
            __VLS_ctx.showProfessionPopup = true;
        }
    };
    let __VLS_83;
    let __VLS_84;
    var __VLS_85;
    __VLS_21.slots.default;
    var __VLS_21;
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
        ...{ class: ("submit") },
    });
    const __VLS_88 = {}.VanButton;
    /** @type { [typeof __VLS_components.VanButton, typeof __VLS_components.vanButton, typeof __VLS_components.VanButton, typeof __VLS_components.vanButton, ] } */ ;
    // @ts-ignore
    const __VLS_89 = __VLS_asFunctionalComponent(__VLS_88, new __VLS_88({
        ...{ 'onClick': {} },
        round: (true),
        block: (true),
        type: ("primary"),
    }));
    const __VLS_90 = __VLS_89({
        ...{ 'onClick': {} },
        round: (true),
        block: (true),
        type: ("primary"),
    }, ...__VLS_functionalComponentArgsRest(__VLS_89));
    let __VLS_94;
    const __VLS_95 = {
        onClick: (...[$event]) => {
            __VLS_ctx.onSubmit();
        }
    };
    let __VLS_91;
    let __VLS_92;
    __VLS_93.slots.default;
    var __VLS_93;
    const __VLS_96 = {}.VanPopup;
    /** @type { [typeof __VLS_components.VanPopup, typeof __VLS_components.vanPopup, typeof __VLS_components.VanPopup, typeof __VLS_components.vanPopup, ] } */ ;
    // @ts-ignore
    const __VLS_97 = __VLS_asFunctionalComponent(__VLS_96, new __VLS_96({
        show: ((__VLS_ctx.showBirthdayPopup)),
        round: (true),
        position: ("bottom"),
    }));
    const __VLS_98 = __VLS_97({
        show: ((__VLS_ctx.showBirthdayPopup)),
        round: (true),
        position: ("bottom"),
    }, ...__VLS_functionalComponentArgsRest(__VLS_97));
    const __VLS_102 = {}.VanDatePicker;
    /** @type { [typeof __VLS_components.VanDatePicker, typeof __VLS_components.vanDatePicker, ] } */ ;
    // @ts-ignore
    const __VLS_103 = __VLS_asFunctionalComponent(__VLS_102, new __VLS_102({
        ...{ 'onCancel': {} },
        ...{ 'onConfirm': {} },
        modelValue: ((__VLS_ctx.currentDate)),
        title: ("选择日期"),
        minDate: ((new Date('1980-01-01'))),
    }));
    const __VLS_104 = __VLS_103({
        ...{ 'onCancel': {} },
        ...{ 'onConfirm': {} },
        modelValue: ((__VLS_ctx.currentDate)),
        title: ("选择日期"),
        minDate: ((new Date('1980-01-01'))),
    }, ...__VLS_functionalComponentArgsRest(__VLS_103));
    let __VLS_108;
    const __VLS_109 = {
        onCancel: (...[$event]) => {
            __VLS_ctx.showBirthdayPopup = false;
        }
    };
    const __VLS_110 = {
        onConfirm: (__VLS_ctx.onChangeBirthday)
    };
    let __VLS_105;
    let __VLS_106;
    var __VLS_107;
    __VLS_101.slots.default;
    var __VLS_101;
    const __VLS_111 = {}.VanPopup;
    /** @type { [typeof __VLS_components.VanPopup, typeof __VLS_components.vanPopup, typeof __VLS_components.VanPopup, typeof __VLS_components.vanPopup, ] } */ ;
    // @ts-ignore
    const __VLS_112 = __VLS_asFunctionalComponent(__VLS_111, new __VLS_111({
        show: ((__VLS_ctx.showLocationPopup)),
        round: (true),
        position: ("bottom"),
    }));
    const __VLS_113 = __VLS_112({
        show: ((__VLS_ctx.showLocationPopup)),
        round: (true),
        position: ("bottom"),
    }, ...__VLS_functionalComponentArgsRest(__VLS_112));
    const __VLS_117 = {}.VanArea;
    /** @type { [typeof __VLS_components.VanArea, typeof __VLS_components.vanArea, typeof __VLS_components.VanArea, typeof __VLS_components.vanArea, ] } */ ;
    // @ts-ignore
    const __VLS_118 = __VLS_asFunctionalComponent(__VLS_117, new __VLS_117({
        ...{ 'onConfirm': {} },
        ...{ 'onCancel': {} },
        areaList: ((__VLS_ctx.areaColumns)),
        title: ("选择省市区"),
    }));
    const __VLS_119 = __VLS_118({
        ...{ 'onConfirm': {} },
        ...{ 'onCancel': {} },
        areaList: ((__VLS_ctx.areaColumns)),
        title: ("选择省市区"),
    }, ...__VLS_functionalComponentArgsRest(__VLS_118));
    let __VLS_123;
    const __VLS_124 = {
        onConfirm: (__VLS_ctx.onSelectedLocation)
    };
    const __VLS_125 = {
        onCancel: (...[$event]) => {
            __VLS_ctx.showLocationPopup = false;
        }
    };
    let __VLS_120;
    let __VLS_121;
    var __VLS_122;
    __VLS_116.slots.default;
    var __VLS_116;
    const __VLS_126 = {}.VanPopup;
    /** @type { [typeof __VLS_components.VanPopup, typeof __VLS_components.vanPopup, typeof __VLS_components.VanPopup, typeof __VLS_components.vanPopup, ] } */ ;
    // @ts-ignore
    const __VLS_127 = __VLS_asFunctionalComponent(__VLS_126, new __VLS_126({
        show: ((__VLS_ctx.showProfessionPopup)),
        round: (true),
        position: ("bottom"),
    }));
    const __VLS_128 = __VLS_127({
        show: ((__VLS_ctx.showProfessionPopup)),
        round: (true),
        position: ("bottom"),
    }, ...__VLS_functionalComponentArgsRest(__VLS_127));
    const __VLS_132 = {}.VanPicker;
    /** @type { [typeof __VLS_components.VanPicker, typeof __VLS_components.vanPicker, ] } */ ;
    // @ts-ignore
    const __VLS_133 = __VLS_asFunctionalComponent(__VLS_132, new __VLS_132({
        ...{ 'onConfirm': {} },
        ...{ 'onCancel': {} },
        columns: ((__VLS_ctx.columns)),
    }));
    const __VLS_134 = __VLS_133({
        ...{ 'onConfirm': {} },
        ...{ 'onCancel': {} },
        columns: ((__VLS_ctx.columns)),
    }, ...__VLS_functionalComponentArgsRest(__VLS_133));
    let __VLS_138;
    const __VLS_139 = {
        onConfirm: (__VLS_ctx.onChangeProfession)
    };
    const __VLS_140 = {
        onCancel: (...[$event]) => {
            __VLS_ctx.showProfessionPopup = false;
        }
    };
    let __VLS_135;
    let __VLS_136;
    var __VLS_137;
    __VLS_131.slots.default;
    var __VLS_131;
    ['profile-edit-page', 'avatar', 'avatar-img', 'avatar-btn', 'gender', 'submit',];
    var __VLS_slots;
    var $slots;
    let __VLS_inheritedAttrs;
    var $attrs;
    const __VLS_refs = {};
    var $refs;
    var $el;
    return {
        attrs: {},
        slots: __VLS_slots,
        refs: $refs,
        rootEl: $el,
    };
}
;
const __VLS_self = (await import('vue')).defineComponent({
    setup() {
        return {
            showAvatarSheet: showAvatarSheet,
            onSelectAvatar: onSelectAvatar,
            showBirthdayPopup: showBirthdayPopup,
            onChangeBirthday: onChangeBirthday,
            currentDate: currentDate,
            areaColumns: areaColumns,
            showLocationPopup: showLocationPopup,
            onSelectedLocation: onSelectedLocation,
            columns: columns,
            showProfessionPopup: showProfessionPopup,
            onChangeProfession: onChangeProfession,
            profile: profile,
            onSubmit: onSubmit,
        };
    },
});
export default (await import('vue')).defineComponent({
    setup() {
        return {};
    },
    __typeEl: {},
});
; /* PartiallyEnd: #4569/main.vue */
